package cz.cuni.mff.d3s.arcas.generator.alloy.ui;

import cz.cuni.mff.d3s.arcas.DRDLRuntimeModule;
import cz.cuni.mff.d3s.arcas.generator.alloy.AlloyGeneratorModule;
import cz.cuni.mff.d3s.arcas.ui.DRDLUiModule;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.xtext.ui.shared.SharedStateModule;
import org.eclipse.xtext.util.Modules2;
import org.osgi.framework.BundleContext;

import com.google.inject.Guice;
import com.google.inject.Injector;

/**
 * The activator class controls the plug-in life cycle
 */
public class Activator extends AbstractUIPlugin {
	private Injector injector;
	private static Activator INSTANCE;

	public Injector getInjector() {
		return injector;
	}

	@Override
	public void start(BundleContext context) throws Exception {
		super.start(context);
		INSTANCE = this;
		injector = Guice.createInjector(
				Modules2.mixin(
						new DRDLRuntimeModule(),
						new SharedStateModule(),
						new DRDLUiModule(this),
						new AlloyGeneratorModule(),
						new AlloyGeneratorUIModule(this)
				)
		);
	}

	@Override
	public void stop(BundleContext context) throws Exception {
		injector = null;
		super.stop(context);
	}

	public static Activator getInstance() {
		return INSTANCE;
	}

}